package com.chance.cc.crawler.development.command.schedule.dxy;

import com.chance.cc.crawler.core.CrawlerJob;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.development.command.job.domain.dxy.normal.DXYForumCrawlerSchedulerJob;
import com.chance.cc.crawler.development.command.job.domain.dxy.normal.DXYNewsCrawlerSchedulerJob;
import com.chance.cc.crawler.development.command.job.domain.dxy.simple.DXYForumSimpleCrawlerSchedulerJob;
import com.chance.cc.crawler.development.command.job.domain.dxy.simple.DXYNewsSimpleCrawlerSchedulerJob;
import com.chance.cc.crawler.development.command.job.domain.dxy.trace.DXYForumTraceCrawlerSchedulerJob;
import com.chance.cc.crawler.development.command.job.domain.dxy.trace.DXYNewsTraceCrawlerSchedulerJob;
import com.chance.cc.crawler.development.command.schedule.CrawlerJobScheduleCommand;
import org.junit.Test;

/**
 * @author lt
 * @version 1.0
 * @date 2021-02-05 18:21:32
 * @email okprog@sina.com
 */
public class DXYCrawlerJobScheduler {
    private static String domain = "dxy";
    private static CrawlerJobScheduleCommand crawlerJobScheduleCommand =
            new CrawlerJobScheduleCommand("192.168.1.215",9589);
    private static String device_name = "crawler_dev_host";

    public static void main(String[] args) {
        republishCrawlerJobSchedule(DXYForumSimpleCrawlerSchedulerJob.dxyScheduler());
//        republishCrawlerJobSchedule(DXYNewsSimpleCrawlerSchedulerJob.dxyScheduler());
    }

    public static void republishCrawlerJobSchedule(CrawlerJob crawlerJob){
        crawlerJobScheduleCommand.republishCrawlerJob(crawlerJob.generateCrawlerTriggerKey(),device_name);
    }

    /**
     * 删除调度
     */
    @Test
    public void delSchedulerJob(){
        CrawlerJob crawlerJob = DXYNewsTraceCrawlerSchedulerJob.dxyScheduler();
        String triggerKey = crawlerJob.generateCrawlerTriggerKey();
        HttpPage httpPage = crawlerJobScheduleCommand.deleteCrawlerJob(triggerKey, device_name);
        System.out.println("delete crawler job : " + httpPage.getRawText());
    }


    @Test
    public void DXYNewsRealtimeJobScheduler(){
        CrawlerJob crawlerJob = DXYNewsCrawlerSchedulerJob.dxyScheduler();
        String triggerKey = crawlerJob.generateCrawlerTriggerKey();
//        crawlerJobScheduleCommand.publishCrawlerJob(triggerKey,device_name);
        crawlerJobScheduleCommand.republishCrawlerJob(triggerKey,device_name);
    }
    @Test
    public void DXYNewsTraceJobScheduler(){
        CrawlerJob crawlerJob = DXYNewsTraceCrawlerSchedulerJob.dxyScheduler();
        String triggerKey = crawlerJob.generateCrawlerTriggerKey();
//        crawlerJobScheduleCommand.publishCrawlerJob(triggerKey,device_name);
        crawlerJobScheduleCommand.republishCrawlerJob(triggerKey,device_name);
    }

    @Test
    public void DXYForumRealtimeJobScheduler(){
        CrawlerJob crawlerJob = DXYForumCrawlerSchedulerJob.dxyScheduler();
        String triggerKey = crawlerJob.generateCrawlerTriggerKey();
//        crawlerJobScheduleCommand.publishCrawlerJob(triggerKey,device_name);
        crawlerJobScheduleCommand.republishCrawlerJob(triggerKey,device_name);
    }
    @Test
    public void DXYForumTraceJobScheduler(){
        CrawlerJob crawlerJob = DXYForumTraceCrawlerSchedulerJob.dxyScheduler();
        String triggerKey = crawlerJob.generateCrawlerTriggerKey();
//        crawlerJobScheduleCommand.publishCrawlerJob(triggerKey,device_name);
        crawlerJobScheduleCommand.republishCrawlerJob(triggerKey,device_name);
    }

}
